/**
* 
* GUI: Gant X-Y window  
* Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN  
* Classe: graphXY.java 
* see <a href="{@docRoot}/">Trace for more information</a>
* 
* @author: Urunuela Richard
* @version 3.2
*/

package programme.GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;

import info.monitorenter.gui.chart.IAxis;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.ZoomableChart;
import info.monitorenter.gui.chart.rangepolicies.RangePolicyMinimumViewport;
import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded;
import info.monitorenter.gui.chart.traces.Trace2DSimple;
import info.monitorenter.gui.chart.traces.painters.TracePainterDisc;
import info.monitorenter.util.Range;
/**
 * 
 * @author richard
 *
 */
public class graphXY extends ZoomableChart {
	ITrace2D trace;
	public static enum type{
		LINE, DISC
	}
	type Type=type.LINE;
	
	/**
	 * 
	 */
	public graphXY(){
		super();
		this.setFont(new Font("Dialog.plain",Font.PLAIN,10));
		this.getAxisX().setAxisTitle(new IAxis.AxisTitle("Time in slot"));
		
		trace = new  Trace2DSimple();
		this.getAxisY().setRange(new Range (0,this.getAxisY().getMax()));
		this.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range (0,this.getAxisY().getMax())  ));
		this.zoom(0, 51);
		
		
	}
	/**
	 * 
	 * @param T
	 */
	public void setYTile(String T){
		this.getAxisY().setAxisTitle(new IAxis.AxisTitle(T));
		
	}
	public void zoomall(){
		super.zoomAll();
		this.getAxisY().setRange(new Range (0,this.getAxisY().getMax()));
		this.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range (0,this.getAxisY().getMax())  ));

	}
	public void zoom (double min, double max){
		super.zoom(min, max);
		this.getAxisY().setRange(new Range (0,this.getAxisY().getMax()));
		this.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range (0,this.getAxisY().getMax())  ));
	}
	/**
	 * 
	 */
	public void mousePressed(MouseEvent e){
		super.mousePressed(e);
		 int buttonDown = e.getButton();

		if((buttonDown == MouseEvent.BUTTON2)||(buttonDown == MouseEvent.BUTTON3) ){
	        this.zoomAll();
			this.getAxisY().setRange(new Range (0,this.getAxisY().getMax()));
			this.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range (0,this.getAxisY().getMax())  ));

	    }

	}
	/**
	 * 
	 * @param date (x)
	 * @param pred value to draw
	 */
	public void addPoint(int date, double pred) {
		this.trace.addPoint(date, pred);
		
		
	}
	/**
	 *  line plot or disc plot (dvfs graph)
	 */
	public void draw() {
		if (this.Type.ordinal() == type.DISC.ordinal()) {
		TracePainterDisc tracePainterDisc = new TracePainterDisc(6);
		
		trace.setTracePainter(tracePainterDisc);
		}
		trace.setColor(Color.RED);
		this.addTrace(this.trace);
	
		
	}
	/**
	 * 
	 * @param string
	 */
	public void setLegend(String string) {
		this.trace.setName(string);
		
		
	}
	/**
	 *  disc or line 
	 * @return
	 */
	public type getType() {
		return Type;
	}
	/**
	 * 
	 * @param type
	 */
	public void setType(type type) {
		Type = type;
	}
	
	
	

}
